<template>
  <div class="root">
    <div class="title"><h1>&nbsp;&nbsp;· 回收站</h1></div>
    <el-table
    :data="tableData"
    style="width: 100%"
    ref="table">
      <el-table-column
        label="日期"
        width="180">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ date }}</span>
      </el-table-column>
      <el-table-column
          prop="name"
          label="商品名称"
          width="360">
      </el-table-column>
      <el-table-column
          prop="num"
          label="订单数量"
          width="360">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">还原</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button icon="el-icon-top-left" class="back" @click="back" ref="top"></el-button>
  </div>
</template>

<script>
import axios from 'axios'
import api from "../../api/index"
  export default {
    name: '',
    data() {
      return {
        date:'2022-2-22',
        tableData: []
      }
    },
    computed: {
      // showUi() {
      //   if(this.tableData) {
      //     this.$refs.empty.style = "none"
      //     this.$refs.table.style = "block"
      //   } else {
      //     this.$refs.table.style = "none"
      //     this.$refs.empty.style = "none"
      //   }
      //   return ""
      // }
    },
    methods: {
      // 还原操作，回收站数据的删除 与 money 数据的添加
      handleEdit(index, row) {
        this.$confirm("是否还原?", "提示！", {
          type: "warning",
        }).then(() => {
          axios
            .delete(`http://localhost:3001/delData/${row.id}`)
            .then((res) => {
              this.updateData()
            });
          axios
            .post(" http://localhost:3001/money", {
              name: row.name,
              num: row.num,
            })
        })
        this.updateData()
      },
      // 数据请求(查)
      updateData() {
        api.money.getDelData().then((res) => {
          this.tableData = res.data
          // console.log(this.tableData);
        })
      },
      // 返回财务页面
      back() {
        this.$router.push("/page2");
      }
    },
    mounted() {
      this.updateData()
    }
  };
</script>

<style scoped lang = 'less'>
.root {
  .title {
      h1 {
        font-size: 20px;
        line-height: 50px;
        color: #666;
        margin-bottom: 20px;
        height: 50px;
        width: 1296px;
        background-color: white;
        border-radius: 7px;
      }
    }
  .el-table {
    height: 100%;
  }
  .back {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    position: fixed;
    right: 30px;
    bottom: 60px;
    background-color: white;
  }
}
</style>